package nciae.db.utils;

import nciae.db.pojo.vo.ExportVO;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.List;

public class ExcelExportUtil {

    public static Workbook exportClassStudents(List<ExportVO> exportVOList) {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("班级成员");

        String[] headers = {"姓名", "所属单位", "电话", "项目名称", "专家名称"};
        Row headerRow = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(headers[i]);
        }

        for (int i = 0; i < exportVOList.size(); i++) {
            Row row = sheet.createRow(i + 1);
            ExportVO exportVO = exportVOList.get(i);

            row.createCell(0).setCellValue(exportVO.getName());
            row.createCell(1).setCellValue(exportVO.getDepartment());
            row.createCell(2).setCellValue(exportVO.getTel());
            row.createCell(3).setCellValue(exportVO.getProjectName());
            row.createCell(4).setCellValue(exportVO.getExpertName());
        }

        return workbook;
    }
}
